var prefix = jsctx + "/tenantInvoiceInfo";

var stationInvoice = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;
    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageCountStationInvoice",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 10,
                    pageList: [10,20,30],
                    // pageList: [10],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo:true,
                    height:h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            startTime: $('#startTime').val(),
                            endTime: $('#endTime').val(),
                            elecStationId: $('#elecStationId').val(),
                            stationName: $('#stationName').val().trim(),
                            equipmentHlhtOperatorId:$("#equipmentHlhtOperatorId").val(),
                            orderType:$("#orderType").val()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '',width:'30',align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'stationName', title: '桩群', width:'150',align: 'left'},
                        {field: 'hlhtOperatorName', title: '设备运营商', width: '120', align: 'left',},
                        {
                            field: '',title:'订单类型',width:'50',align:'left',
                            formatter:function (value,row,index) {
                                if($("#orderType").val()=='0'){
                                    return "个人订单";
                                } else if ($("#orderType").val()=='1'){
                                    return "企业订单";
                                } else if ($("#orderType").val()=='2'){
                                    return "反向订单";
                                } else {
                                    return "";
                                }
                            }
                        },
                        {field: 'totalPower', title: '电量', width:'50',align: 'right'},
                        {field: 'totalElecMoney', title: '电费', width:'50',align: 'right'},
                        {field: 'totalSeviceMoney', title: '服务费', width:'50',align: 'right'},
                        {field: 'discountAmount', title: '优惠金额', width:'50',align: 'right'},
                        {field: 'payAmount', title: '开票金额', width:'50',align: 'right'},


                        {
                            title: '操作',
                            field: 'roleId',
                            width:'50',align: 'center',
                            formatter: function (value, row, index) {
                                var a = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="导出" onclick="stationInvoice.exportStationInvoiceDetail('
                                    + row.elecStationId
                                    + ')">导出</a> ';
                                return a ;
                            }
                        }
                    ]
                });
    };

    /**
     * 查询
     */
    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    };


    /**
     * 导出桩群发票详情列表
     *
     */
    function exportStationInvoiceDetail(elecStationId) {
        $.fileDownload(prefix + "/exportStationInvoiceDetail", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                startTime: $('#startTime').val(),
                endTime: $('#endTime').val(),
                elecStationId: elecStationId,
                stationName: $('#stationName').val(),
                equipmentHlhtOperatorId:$("#equipmentHlhtOperatorId").val(),
                orderType:$("#orderType").val()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...",{time:-1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！",{time:1500});
            },
            failCallback: function (data) {
                var str = "{"+data.substring(data.indexOf("{")+1,data.indexOf("}"))+"}";
                layer.msg(JSON.parse(str).message);
            }
        })
    };

    /**
     * 导出桩群发票列表
     *
     */
    function exportStationInvoice(elecStationId) {
        $.fileDownload(prefix + "/exportStationInvoice", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                startTime: $('#startTime').val(),
                endTime: $('#endTime').val(),
                elecStationId: elecStationId,
                stationName: $('#stationName').val(),
                equipmentHlhtOperatorId:$("#equipmentHlhtOperatorId").val(),
                orderType:$("#orderType").val(),
                count:$("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...",{time:-1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！",{time:1500});
            },
            failCallback: function (data) {
                var str = "{"+data.substring(data.indexOf("{")+1,data.indexOf("}"))+"}";
                layer.msg(JSON.parse(str).message);
            }
        })
    };


    /**
     * 返回列表
     */
    function goBack() {
        location.href = prefix + "/index";
    };

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        exportStationInvoiceDetail:exportStationInvoiceDetail,
        exportStationInvoice:exportStationInvoice
    };
})();



